import axios from 'axios'

class Request {
  http(options) {
    options.url = Request.PROTOCOL + Request.HOST + options.url;
    return axios(options)
      .then(res => {
        if (res.status === 200) {
          return res.data;
        }
        return null;
      })
      .catch(err => console.log(err));
  }

  get(url, options = null) {
    return this.http({
      url,
      method: 'get',
      ...options
    });
  }

  post(url, options = null) {
    return this.http({
      url,
      method: 'post',
      ...options
    });
  }
}

Request.HOST = '111.229.208.85/apis';
Request.PROTOCOL = 'http://';

export default new Request();
export const HOST = Request.HOST;
export const PROTOCOL = Request.PROTOCOL;